scale: Make draw-value default to FALSE
authorMatthias Clasen <mclasen@redhat.com>
Sun, 4 Oct 2020 00:08:29 +0000 (20:08 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 4 Oct 2020 12:26:44 +0000 (08:26 -0400)
This is rarely what you want, so lets turn it off
by default.

Update the one place in our demos where we want to
draw a value, add support for this to gtk-builder-tool,
add a test and mention this change in the migration
guide.

demos/widget-factory/widget-factory.ui
docs/reference/gtk/migrating-3to4.md
gtk/gtkscale.c
gtk/tools/gtk-builder-tool-simplify.c
testsuite/css/nodes/scale.ui
testsuite/gtk/focus-chain/widget-factory.ui
testsuite/gtk/focus-chain/widget-factory2.ui
testsuite/gtk/focus-chain/widget-factory3.ui
testsuite/tools/simplify-data-3to4/scale.expected [new file with mode: 0644]
testsuite/tools/simplify-data-3to4/scale.ui [new file with mode: 0644]

index 139ef083e0fdf55f9b2f7cff0e31a438df97c435..0b383655ee7c9a8d99d6f54b3bdd8ba608d2d2ae 100644 (file)
@@ -1011,6 +1011,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
                                         <property name="restrict-to-fill-level">0</property>
                                         <property name="fill-level">75</property>
                                         <property name="digits">-1</property>
+                                        <property name="draw-value">1</property>
                                         <property name="halign">end</property>
                                       </object>
                                     </child>
@@ -1023,6 +1024,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
                                         <property name="restrict-to-fill-level">0</property>
                                         <property name="fill-level">75</property>
                                         <property name="digits">-1</property>
+                                        <property name="draw-value">1</property>
                                         <property name="halign">start</property>
                                       </object>
                                     </child>
index 429e7c7421c5efb593b9dd9381e5e8e350222713..8e19740e129a5cbec4ba72e4234cbe410b2abf0f 100644 (file)
@@ -891,6 +891,15 @@ gtk_search_entry_handle_event() has been dropped and replaced by
 gtk_search_entry_set_key_capture_widget() and
 gtk_event_controller_key_forward().
 
+### Adapt to GtkScale changes
+
+The default value of #GtkScale:draw-value has been changed to %FALSE.
+If you want your scales to draw values, you will have to set this
+property explicitly now.
+
+gtk4-builder-tool can help with this conversion, with the --3to4 option
+of the simplify command.
+
 ### Stop using gtk_window_activate_default()
 
 The handling of default widgets has been changed, and activating
index c604642bff08da1a0e552f1c8297a596b84641e5..d9928636cf6cede4c3eac91e89f2a6dc5856c29f 100644 (file)
@@ -684,7 +684,7 @@ gtk_scale_class_init (GtkScaleClass *class)
       g_param_spec_boolean ("draw-value",
                             P_("Draw Value"),
                             P_("Whether the current value is displayed as a string next to the slider"),
-                            TRUE,
+                            FALSE,
                             GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
 
   properties[PROP_HAS_ORIGIN] =
@@ -839,7 +839,6 @@ gtk_scale_init (GtkScale *scale)
 
   _gtk_range_set_has_origin (range, TRUE);
 
-  gtk_scale_set_draw_value (scale, TRUE);
   gtk_range_set_round_digits (range, priv->digits);
 
   gtk_range_set_flippable (range, TRUE);
index 0650f54941f7d416f2b68528116927c0a2dce666..f2f57d8eab8bf0556dfad7b55de34ea21d140695 100644 (file)
@@ -1770,6 +1770,45 @@ rewrite_radio_button (Element      *element,
     }
 }
 
+static gboolean
+has_prop (Element      *element,
+          MyParserData *data,
+          const char   *prop_name)
+{
+  GList *l;
+
+  for (l = element->children; l; l = l->next)
+    {
+      Element *child = l->data;
+
+      if (g_str_equal (child->element_name, "property") &&
+          has_attribute (child, "name", prop_name))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
+static void
+rewrite_scale (Element      *element,
+               MyParserData *data)
+{
+  if (!has_prop (element, data, "draw-value") &&
+      !has_prop (element, data, "draw_value"))
+    {
+      Element *child;
+      child = g_new0 (Element, 1);
+      child->parent = element;
+      child->element_name = g_strdup ("property");
+      child->attribute_names = g_new0 (char *, 2);
+      child->attribute_names[0] = g_strdup ("name");
+      child->attribute_values = g_new0 (char *, 2);
+      child->attribute_values[0] = g_strdup ("draw-value");
+      child->data = g_strdup ("1");
+      element->children = g_list_prepend (element->children, child);
+    }
+}
+
 /* returns TRUE to remove the element from the parent */
 static gboolean
 simplify_element (Element      *element,
@@ -1919,6 +1958,10 @@ rewrite_element (Element      *element,
       g_str_equal (get_class_name (element), "GtkRadioButton"))
     rewrite_radio_button (element, data);
 
+  if (element_is_object_or_template (element) &&
+      g_str_equal (get_class_name (element), "GtkScale"))
+    rewrite_scale (element, data);
+
   if (g_str_equal (element->element_name, "property"))
     maybe_rename_property (element, data);
 
index b71f90a77a88229bb2d565490615e40446e6c10f..1c7eb2c2519a884bf079874275bcd761709934a2 100644 (file)
@@ -23,6 +23,7 @@
             <property name="visible">True</property>
             <property name="orientation">horizontal</property>
             <property name="adjustment">adjustment1</property>
+            <property name="draw-value">1</property>
           </object>
         </child>
         <child>
@@ -31,6 +32,7 @@
             <property name="orientation">horizontal</property>
             <property name="adjustment">adjustment1</property>
             <property name="value-pos">bottom</property>
+            <property name="draw-value">1</property>
           </object>
         </child>
         <child>
index c090dbf22879b537822593e93ba258a5c5fb191c..f3aa01b9fe3b8b86e14b8bb78ea814f5ec60cb6c 100644 (file)
@@ -1014,6 +1014,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
                                         <property name="restrict-to-fill-level">0</property>
                                         <property name="fill-level">75</property>
                                         <property name="digits">-1</property>
+                                        <property name="draw-value">1</property>
                                         <property name="halign">end</property>
                                       </object>
                                     </child>
@@ -1026,6 +1027,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
                                         <property name="restrict-to-fill-level">0</property>
                                         <property name="fill-level">75</property>
                                         <property name="digits">-1</property>
+                                        <property name="draw-value">1</property>
                                         <property name="halign">start</property>
                                       </object>
                                     </child>
index cfc151da114ad4b946cbe60b7eb00cf46297c5e7..3f5c3bb0d38572494b7cd5a9f62f6d7825e1c4b0 100644 (file)
@@ -1015,6 +1015,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
                                         <property name="restrict-to-fill-level">0</property>
                                         <property name="fill-level">75</property>
                                         <property name="digits">-1</property>
+                                        <property name="draw-value">1</property>
                                         <property name="halign">end</property>
                                       </object>
                                     </child>
@@ -1027,6 +1028,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
                                         <property name="restrict-to-fill-level">0</property>
                                         <property name="fill-level">75</property>
                                         <property name="digits">-1</property>
+                                        <property name="draw-value">1</property>
                                         <property name="halign">start</property>
                                       </object>
                                     </child>
index 9f454b90c22b572673a323fc19c43a522ea71f20..de944471efb2f1c960488b9b4ab3cb8767bd0ef9 100644 (file)
@@ -1015,6 +1015,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
                                         <property name="restrict-to-fill-level">0</property>
                                         <property name="fill-level">75</property>
                                         <property name="digits">-1</property>
+                                        <property name="draw-value">1</property>
                                         <property name="halign">end</property>
                                       </object>
                                     </child>
@@ -1027,6 +1028,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
                                         <property name="restrict-to-fill-level">0</property>
                                         <property name="fill-level">75</property>
                                         <property name="digits">-1</property>
+                                        <property name="draw-value">1</property>
                                         <property name="halign">start</property>
                                       </object>
                                     </child>
diff --git a/testsuite/tools/simplify-data-3to4/scale.expected b/testsuite/tools/simplify-data-3to4/scale.expected
new file mode 100644 (file)
index 0000000..20e71ab
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkScale">
+    <property name="draw-value">1</property>
+    <property name="visible">0</property>
+  </object>
+  <object class="GtkScale">
+    <property name="visible">0</property>
+    <property name="draw-value">1</property>
+  </object>
+  <object class="GtkScale">
+    <property name="visible">0</property>
+  </object>
+</interface>
diff --git a/testsuite/tools/simplify-data-3to4/scale.ui b/testsuite/tools/simplify-data-3to4/scale.ui
new file mode 100644 (file)
index 0000000..279b797
--- /dev/null
@@ -0,0 +1,10 @@
+<interface>
+  <object class="GtkScale">
+  </object>
+  <object class="GtkScale">
+    <property name="draw-value">1</property>
+  </object>
+  <object class="GtkScale">
+    <property name="draw_value">0</property>
+  </object>
+</interface>